|
|
|
|
|
|
|
The following code displays a list of the printers in the Printers collection. |
|
|
|
 |
|
|
|
|
Dim pr As Printer
Dim txt As String
For Each pr In Printers
txt = txt & pr.DeviceName & vbCrLf
Next pr
MsgBox txt |
|
|
|
|
|
|
|
|
Example program Printers, shown in Figure 5.1, uses similar code to list the device names, ports, and drivers for the printers on your system. |
|
|
|
|
|
|
|
|
When you run the Printers program, you may be surprised to find more printers than you expected. Several objects including fax software and graphic subsystems can appear as printers to the operating system. Generally, if an object looks enough like a printer to appear in the Printers collection, you should be able to treat it like a printer. You can draw on it, tell it to print a page, and so forth. |
|
|
|
|
|
|
|
|
Many of these non-printer objects take special actions when you print to them. For instance, you can make the Printer object represent fax software and then use the PrintForm method to send graphics to the Printer object. The fax software might then present a dialog box in which you would enter the name of the person who should receive the fax, the person's phone number, and the style of cover page you want to use. When you finish entering this information, the software would fax the image created by the PrintForm command. |
|
|
|
|
|
|
|
|
The Common Dialog Control that comes with Visual Basic makes it easy for a user to select a printer. When you invoke the control's ShowPrinter method, it presents a dialog that allows the user to select a printer. By pressing the dialog's Properties button, the user can modify many of the selected printer's properties. For example, this button lets the user set the printer's paper size and orientation. |
|
|
|
|
|
|
|
|
Figure 5.1
Example program Printers lists the printer
devices available on the system. |
|
|
|
|
|